package me.pplay.playtalk.util;

import java.util.Calendar;
import java.util.Date;

public class DateParseUtil {
	private static Calendar calendar = Calendar.getInstance();
	private static int pubMonth, pubDay, pubHour, pubMinute;

	public DateParseUtil() {
		calendar = Calendar.getInstance();
	}

	// 1334677104
	public static String getTimeText(long time) {
		Calendar today = Calendar.getInstance();
		today.setTime(new Date());
		Calendar old = Calendar.getInstance();
		old.setTimeInMillis(time);
		calendar.setTimeInMillis(time);

		today.set(Calendar.HOUR_OF_DAY, 0);
		today.set(Calendar.SECOND, 0);
		today.set(Calendar.MINUTE, 0);
		old.set(Calendar.HOUR_OF_DAY, 0);
		old.set(Calendar.SECOND, 0);
		old.set(Calendar.MINUTE, 0);

		long intervalMilli = old.getTimeInMillis() - today.getTimeInMillis();
		int result = (int) (intervalMilli / (24 * 60 * 60 * 1000));
        String str = "";
		if (result != 0) { // 0:当天 
			pubMonth = calendar.get(Calendar.MONTH) + 1;
			pubDay = calendar.get(Calendar.DAY_OF_MONTH);
			String pubMonthStr = pubMonth + "";
			if (pubMonth < 10)
				pubMonthStr = "0" + pubMonthStr;
			String pubDayStr = pubDay + "";
			if (pubDay < 10)
				pubDayStr = "0" + pubDayStr;
			str = pubMonthStr + "-" + pubDayStr + " ";
		}
		pubHour = calendar.get(Calendar.HOUR_OF_DAY);
		pubMinute = calendar.get(Calendar.MINUTE);
		String pubHourStr = pubHour + "";
		if (pubHour < 10)
			pubHourStr = "0" + pubHourStr;
		String pubMinuteStr = pubMinute + "";
		if (pubMinute < 10)
			pubMinuteStr = "0" + pubMinuteStr;
    	return str + pubHourStr + "：" + pubMinuteStr + "";
	}
}
